<?php


namespace App\Services;


use App\Service\Service;
use Dingo\Api\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

/**
 * Class UploadService
 * @property
 * @package App\Services
 * @author thanatos thanatos915@163.com
 */
class UploadService extends Service
{

    /**
     * 上传文件
     * @param Request $request
     * @author thanatos thanatos915@163.com
     */
    public static function upload(Request $request)
    {
        $dir = date('Y-m') . '/' . date('d');

        $disk = Storage::disk('oss');

        $content = $request->file('file');

        $ext = $content->extension();
        $fileName = Str::random(32) . '.' . $ext;

        $res = $disk->putFileAs($dir, $content, $fileName);
        return [
            'path' => $res,
            'original_name' => $content->getClientOriginalName(),
            'size' => $content->getSize()
        ];
    }

}
